package com.hlkj.warboot.module_sys.entity.wrapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hlkj.warboot.configurer.util.StrUtil;
import com.hlkj.warboot.module_sys.entity.MailEntity;

/**
 * @Description: 动态生成QueryWrapper<MailEntity>对象
 * @Author: lixing
 * @Date: 2020/6/12 17:27
 */
public class MailWrapper {
    public static QueryWrapper<MailEntity> queryWrapper(MailEntity entity) {
        QueryWrapper<MailEntity> queryWrapper = new QueryWrapper<>();
        if (entity.baseCreateTimeStart != null) {
            queryWrapper.ge("create_time", entity.baseCreateTimeStart);
        }
        if (entity.baseCreateTimeEnd != null) {
            queryWrapper.le("create_time", entity.baseCreateTimeEnd);
        }
        if (entity.getCreateUserGrade() != null) {
            if (entity.getCreateUserGrade() == 2) {
                queryWrapper.in("create_user_grade", 2, 3, 4);
            } else if (entity.getCreateUserGrade() == 3) {
                queryWrapper.in("create_user_grade", 3, 4);
            } else if (entity.getCreateUserGrade() == 4) {
                queryWrapper.eq("create_user_grade", 4);
            }
//            if (StrUtil.isEffective(entity.getCreateUserAccount())) {
//                queryWrapper.eq("createUserAccount", entity.getCreateUserAccount());
//            }
        }
        if (entity.getCategory() != null) {
            queryWrapper.eq("category", entity.getCategory());
        }
        if (StrUtil.isEffective(entity.getReceiver())) {
            queryWrapper.eq("receiver", entity.getReceiver());
        }

        return queryWrapper;
    }
}
